<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>硅谷健康</title>
    <meta name="description" content="硅谷健康">
    <meta name="keywords" content="硅谷健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->

    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
        .calendar-day{
            text-align: center;
            color: #202535;
            line-height: 30px;
            font-size: 12px;
        }
        .is-selected{
            color: #F8A535;
            font-size: 10px;
            margin-top: 5px;
        }
        #calendar .el-button-group>.el-button:not(:first-child):not(:last-child):after{
            content: '当月';
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>预约列表</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="box ordersetting">
                    <div class="boxMain">
                        <el-button style="margin-bottom: 20px;margin-right: 20px" type="primary" @click="downloadTemplate()">模板下载</el-button>
                        <el-upload action="/ordersetting/upload.do"
                                   name="excelFile"
                                   :show-file-list="false"
                                   :on-success="handleSuccess"
                                   :before-upload="beforeUpload">
                            <el-button type="primary">上传文件</el-button>
                        </el-upload>
                    </div>
                    <div>
                        操作说明：请点击"模板下载"按钮获取模板文件，在模板文件中录入预约设置数据后点击"上传文件"按钮上传模板文件。
                    </div>
                <el-calendar v-model="value">
                    <template
                            slot="dateCell"
                            slot-scope="{date, data}">
                        <!--自定义内容-->
                        <div>
                            <div class="calendar-day">{{ data.day.split('-').slice(2).join('-') }}</div>
                            <div v-for="item in calendarData">
                                <div v-if="(item.months).indexOf(data.day.split('-').slice(1)[0])!=-1">
                                    <div v-if="(item.days).indexOf(data.day.split('-').slice(2).join('-'))!=-1">
                                        <el-tooltip class="item" effect="dark" :content="item.reservations" placement="right">
                                            <div class="is-selected">可预约的人数:{{item.number}}</div>
                                        </el-tooltip>
                                        <el-tooltip class="item" effect="dark" :content="item.number" placement="right">
                                            <div class="is-selected">已预约的人数:{{item.reservations}}</div>
                                        </el-tooltip>
                                    </div>
                                    <div v-else></div>
                                </div>
                                <div v-else></div>
                            </div>
                        </div>
                    </template>
                </el-calendar>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data:{
            activeName:'first',//添加/编辑窗口Tab标签名称
            calendarData: [
                { months: ['04'], days: ['02'],number:'100',reservations: '10' },
                { months: ['04'], days: ['01'],number:'100',reservations: '20' }
            ],
            value: new Date(),
            dataList: [],//列表数据
            formData: {},//表单数据
            tableData:[],//新增和编辑表单中对应的检查项列表数据
            OrderSetting:[],
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit:false//控制编辑窗口显示/隐藏
        },
        methods: {
            dealMyDate() {
                console.log(this.value)
            },
            //上传之前进行文件格式校验
            beforeUpload(file) {
                const isXLS = file.type === 'application/vnd.ms-excel';
                if (isXLS) {
                    return true;
                }
                const isXLSX = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
                if (isXLSX) {
                    return true;
                }
                this.$message.error('上传文件只能是xls或者xlsx格式!');
                return false;
            },
            //下载模板文件
            downloadTemplate() {
                window.location.href = "../../template/ordersetting_template.xlsx";
            },
            //上传成功提示
            handleSuccess(response, file) {
                if (response.flag) {
                    this.$message({
                        message: response.message,
                        type: 'success'
                    });
                } else {
                    this.$message.error(response.message);
                }
                console.log(response, file, fileList);
            },
            //添加
            handleAdd() {
                alert("formData:" + this.formData)
                //发送ajax请求
                axios.post("/order/add.do", this.formData)
                    .then((response => {
                        //关闭新增窗口
                        this.dialogFormVisible = false;
                        if (response.data.flag) {
                            //新增成功,弹出成功提示
                            this.$message({
                                message: response.data.message,
                                type: 'success'
                            })
                        } else {
                            //新增失败
                            this.$message.error(response.data.message);
                        }
                    })).catch(response => {
                    alert("error!");
                }).finally(() => {
                        this.findPage();
                    }
                );
            },
            handleUpdate(row) {
                if (row.orderStatus == 0) {
                    axios.get("/order/updateById.do?id=" + row.id).then((res) => {
                        if (res.data.flag) {
                            //为模型数据设置值,基于VUE双向绑定回显到页面
                            this.$message.success("预约成功");
                            //调用分页
                            this.findPage();
                        } else {
                            this.$message.error("获取数据失败,请刷新当前页面");
                        }
                    });
                }else {
                    this.$message.error("当前状态不能确认预约哦！");
                }
            },
            handleDelete(row) {
                if (row.orderStatus == 2) {
                    this.$message.error("当前状态已经取消预约过了哦！");
                } else {
                    axios.get("/order/updateById2.do?id=" + row.id).then((res) => {
                        if (res.data.flag) {
                            //为模型数据设置值,基于VUE双向绑定回显到页面
                            this.$message.success("取消成功!");
                            //调用分页
                            this.findPage();
                        } else {
                            this.$message.error("取消预约失败!,请刷新当前页面");
                        }
                    });
                }
            },
            // 重置表单
            resetForm() {
                this.formData = {};
            },
            // 弹出添加窗口
            handleCreate() {
                this.resetForm();
                this.dialogFormVisible = true;
                //默认切换到第一个标签页(基本信息)
                this.activeName = 'first';
                //重置:
                this.members = [];
                //发送ajax请求查询所有检查项信息
                axios.get("/order/findAll.do").then((res => {
                    if (res.data.flag) {
                        //this.tableData=res.data.data;
                        //console.log(res.data.data)
                        this.OrderSetting = res.data.data;
                    } else {
                        this.$message.error(res.data.message);
                    }
                }));
            }
        }
    })
</script>
</html>
